<?php

/*
 * 网站配置文件管理
 */

class Config {

    /**
     * 更新网站的配置文件缓存
     * @param string $type 要更新的配置文件的类型
     */
    public static function updateConfig($type) {
        global $_SGLOBAL;
        $config = array();

        switch ($type) {
            case 'email':
                $sql = "SELECT * FROM " . Utils::tname('emailtemplate');
                $variable = "_SCONFIG['email']";
                $file='data_email.php';
                break;
            case 'config':
                $sql = "SELECT * FROM " . Utils::tname('config');
                $variable = '_SCONFIG';
                $file='data_config.php';
                break;
            default :
        }
        if ($type == 'email') {
            $query = $_SGLOBAL['db']->query($sql);
            while ($row = $_SGLOBAL['db']->fetchArray($query)) {
                $config[$row['id']] = $row;
            }
        } elseif ($type == 'config') {
            $query = $_SGLOBAL['db']->query($sql);
            while ($row = $_SGLOBAL['db']->fetchArray($query)) {
                $config[$row['variable']] = $row['value'];
            }
        }
        Utils::arrayTOFile($variable, $config, S_ROOT . "/data/$file");
    }

}

?>
